﻿using System.Collections;
using System.Collections.Generic;
using System.Reflection;

namespace FluentlyXml.Core.Deserialization
{
	internal class PropertyDeserializerDictionary : IEnumerable<KeyValuePair<string, PropertyDeserializer>>
	{
		private readonly IDictionary<string, PropertyDeserializer> _propertiesToDeserializers = new Dictionary<string, PropertyDeserializer>();

		//TODO: Eventually, let's not use PropertyInfo here, let's use something else.  Probably not a string
		//		since that's not a strong enough concept...
		public PropertyDeserializer this[PropertyInfo property]
		{
			get { return _propertiesToDeserializers[property.Name]; }
			set { _propertiesToDeserializers[property.Name] = value; }
		}

		public IEnumerator<KeyValuePair<string, PropertyDeserializer>> GetEnumerator()
		{
			return _propertiesToDeserializers.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}

		public void Add(string propertyName, PropertyDeserializer deserializer)
		{
			_propertiesToDeserializers.Add(propertyName, deserializer);
		}
	}
}